<?php

/***************商品品牌****************/
/*******2013-4-30********/

class GoodsbrandAction extends Action
{
	public function preMethod()
	{
		R("Mayijie/check_admin");
		$perm_key = session('admin_perm');
		$perm_arr = explode(",",$perm_key);
		if(!in_array(4,$perm_arr)){
			$this->error("无权操作");
		}
	}

	public function index(){
		$Brand=M('Goods_brand');
		$this->brand=$Brand->order('sorting')->select();
		$this->display();
	}

	public function add(){
		$Brand=D('Goods_brand');
		if($Brand->create()){
		     $result=$Brand->add();
		     if($result){
			    $this->success("添加成功！");
		     }else{
			    $this->error("添加失败！");
		     }
		}else{
			$this->error($Brand->getError());
		}

	}
	//品牌修改
	public function edit(){
		$Brand=M('Goods_brand');
		$bid=$this->_get('bid');
		$this->brand=$Brand->where('brand_id='.$bid)->find();
		$this->display();
	}
	public function save_edit(){
		$Brand=M('Goods_brand');
		$data['brand_name']=$this->_post('bname');
		$data['brand_logo']=$this->_post('blogo');
		$data['brand_url']=$this->_post('burl');
		$data['sorting']=$this->_post('sort');
		$data['is_hot']=$this->_post('ishot');
		$bid=$this->_post('bid');
		$result=$Brand->where('brand_id='.$bid)->save($data);
		if($result){
			echo '1';
		}else{
			echo '0';
		}
	}

	public function get_brand(){
		$Brand=M('Goods_brand');
		return $Brand->order('brand_id desc')->select();
	}

	public function del()
	{
		$map['brand_id'] = intval($this->_get('id'));
		$Brand=M('Goods_brand');
		if($Brand->where($map)->delete()){
			echo 0;
		}else{
			echo 1;
		}
	}
  

}
?>